<?php

namespace mpend\modules\user\models\traits;

use common\models\orange\OrangeShopGoods;
use common\models\orange\OrangeShopModules;
use common\models\orange\OrangeShopModulesGoods;

trait Modules {

    public function getModules() {
        $modules = OrangeShopModules::find()->orderBy('sort desc')->all();
        $arrModules = [];
        foreach ($modules as $module) {
            $arr['goods'] = OrangeShopModulesGoods::find()
            ->alias('module')
            ->innerJoin(OrangeShopGoods::tableName() . ' As orangeShopGood')
            ->select(['orangeShopGood.name', 'orangeShopGood.cover', 'orangeShopGood.orange_price'])
            ->where(['modules_id' => $module->id])
            ->orderBy('module.sort desc')
            ->asArray()
            ->all();

            $arr['module_title'] = $module->title;
            $arr['module_icon'] = $module->icon;
            $arrModules[] = $arr;
        }

        return $arrModules;
    }

}
